package com.example.newlist;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import com.example.newlist.Adapter.MyAdapter;

import java.util.ArrayList;


public class ExpandableListView extends AppCompatActivity {

    private android.widget.ExpandableListView expandableListView;
    ArrayList<bean> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_expandable_list_view);
        expandableListView = findViewById(R.id.expandableListView);
        initView();
    }

    public void initView(){
        for (int i = 0; i < 5; i++) {
            bean bean = new bean("第"+i+"项","子项"+i*i);
            list.add(bean);
        }
        MyAdapter adapter = new MyAdapter(list);
        expandableListView.setAdapter(adapter);
        expandableListView.setOnGroupClickListener(new android.widget.ExpandableListView.OnGroupClickListener()
        {
            @SuppressLint("NewApi")
            @Override
            public boolean onGroupClick(android.widget.ExpandableListView parent, View v, int groupPosition, long id)
            {
                if (list.isEmpty())
                {
                    return true;
                }
                return false;
            }
        });
    }
}